/*---------------------------------------------------------------------
 * File name: hal_system.h
 *
 * Copyright (c) <2020-2022>, <ChenLong>
 *
 * All rights reserved.
 *
 * Author: ChenLong
 * Email: worldlong@foxmail.com
 *--------------------------------------------------------------------*/
#pragma once
/*
*/
#include <cstdint>
#include <cstring>
/*
*/
#define FWD_PSC_DIV4              0
#define FWD_PSC_DIV8              1
#define FWD_PSC_DIV16             2
#define FWD_PSC_DIV32             3
#define FWD_PSC_DIV64             4
#define FWD_PSC_DIV128            5
#define FWD_PSC_DIV256            6 
/*
*/
class HAL_System
{
public:
  HAL_System() {}
  
  void init();
  void close_all_periph();
  void reset();
  void fwd_config(uint16_t counter, uint16_t psc_div);  //counter is 12bits
  void wwd_config(uint16_t counter, uint16_t window, uint16_t psc_div); //counter is 12bits
  void fwd_feed();
  void wwd_feed(uint16_t counter);
  void set_dma_irq_hook(int index, void (*irq_hook)(void *param), void *irq_hook_param);
};
/*
*/
inline void interrupt_disable()
{
  __asm("CPSID  i");
}
/*
*/
inline void interrupt_enable()
{
  __asm("CPSIE  i");
}
/*
*/
inline uint32_t enter_critical()
{
  __asm("MRS  r0, PRIMASK\n"
        "CPSID  i\n"
        "BX  lr");
  return 0;  //Will not reach here, just used to clear the compiling warning
}
/*
*/
inline void exit_critical(uint32_t sr)
{
  __asm("MSR  PRIMASK, r0\n"
        "BX  lr");
}



